/* 
 * Given a sorted linked list, delete all duplicates such that each element appear only once
 * Given 1->1->2, return 1->2
 * Given 1->1->2->3->3, return 1->2->3
 */

#include "../../func.h"

ListNode *deleteDuplicates(ListNode *head)
{
    if (!head)
        return head;
    ListNode dummy(head->val +  1);
    dummy.next = head;

    recur(&dummy, head);
    return dummy.next;
}

void recur(ListNode *prev, ListNode *cur)
{
    if (nullptr == cur)
        return;

    if (prev->val == cur->val)
    {
        prev->next = cur->next;
        delete cur;
        recur(prev, prev->next);
    }
    else
    {
        recur(prev->next, cur->next);
    }  
}